<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script type="text/javascript" src="../js/vue.js"></script>
    <script type="text/javascript" src="../js/axios.min.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/bootstrap.min.js"></script>
    <link type="text/css" rel="stylesheet" href="../css/bootstrap.min.css">
</head>

<body>
    <div id="app" class="container">
        <label>编号：<input type="text" v-model="id"></label>
        <label>姓名：<input type="text" v-model="username" @keyup.f2="addBook"></label>
        <label>性别：<input type="text" v-model="gender"></label>
        <label>出生日期：<input type="text" v-model="birth"></label>
        <button class="btn btn-primary">添加</button>

        <hr>

        <label>搜索：<input type="text" class="form-control" placeholder="请输入书籍的名称" v-model="keywords"></label>
        <button class="btn btn-default" style="margin-left: 10px">搜索</button>


        <table class="table table-hover">
            <thead>
                <tr>
                    <th>编号</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>出生日期</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="item in userList" :key="item.id">
                    <td>{{item.id}}</td>
                    <td>{{item.username}}</td>
                    <td>{{item.gender == 1 ? '男' : '女'}}</td>
                    <td>{{item.birth}}</td>
                </tr>
            </tbody>
        </table>
    </div>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                id: '',
                username: '',
                gender: '',
                birth: '',
                keywords: '',
                userList: null
            },
            methods: {},
            mounted: function() {
                var _this = this;
                axios.get("http://localhost:9000/api/admin/user").then(function(result) {
                    _this.userList = result.data.data;
                }).catch(function(error) { // 请求失败处理
                    console.log(error);
                });;
            }
        });
    </script>
</body>

</html>